clear			all
set 			more off
cd 				"~/Dropbox/Indonesia Migration/" // Specify your root directory here
/*******************************************************************************
				Employment
********************************************************************************/
use				"Data\Merged", clear
label 			var per_immig_cst_5Y "Population share of new migrants in year t"
label 			var per_immig_cst_5Y_lag "Population share of new migrants in year t-5"

foreach 		var in emp native_emp mig_emp_o mig_emp_n ///
				wage native_wage mig_wage_o mig_wage_n ///
				SE native_SE mig_SE_o mig_SE_n ///
				unpaid native_unpaid mig_unpaid_o mig_unpaid_n {
replace			prop_`var' = prop_`var' * 100
}	
/*******************************************************************************
					EMPLOYMENT
********************************************************************************/
ivreg2			prop_emp (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_0_weighted.xlsx", excel tex replace dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_native_emp (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_0_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_mig_emp_o (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_0_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)

ivreg2			prop_mig_emp_n (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_0_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
			
	
/*******************************************************************************
				Wage employment
********************************************************************************/
ivreg2			prop_wage (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_1_weighted.xlsx", excel tex replace dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_native_wage (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_1_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_mig_wage_o (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_1_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)

ivreg2			prop_mig_wage_n (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_1_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
/*******************************************************************************
				Self employment
********************************************************************************/
ivreg2			prop_SE (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_2_weighted.xlsx", excel tex replace dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_native_SE (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_2_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_mig_SE_o (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_2_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)

ivreg2			prop_mig_SE_n (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_2_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)

				
/*******************************************************************************
				Unpaid work
********************************************************************************/
ivreg2			prop_unpaid (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_3_weighted.xlsx", excel tex replace dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_native_unpaid (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_3_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
				
ivreg2			prop_mig_unpaid_o (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_3_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)

ivreg2			prop_mig_unpaid_n (per_immig_cst_5Y per_immig_cst_5Y_lag = ///
				pred_per_immig_cst_10Y_5Y pred_per_immig_cst_Jaeger_10Y) ///
				i.year#i.geolev1 i.geolev2 av_high_educ_ct prop_male_ct av_age_ct ///
				[pweight = pop_cst], cl(geolev1) first	
mat				c = e(first)
local			SWF1= c[8,1]
local			SWF2= c[8,2]
su				`e(depvar)' if e(sample) == 1, d				
local			meandv=r(mean)
outreg2			using "Tables/Employment_3_weighted.xlsx", excel tex append dec(4) ///
				keep(per_immig_cst_5Y per_immig_cst_5Y_lag) label nocons nonotes ///
				addtext("Sanderson-Windmeijer F-Stat 1", `: di %9.2f `SWF1'', ///
				"Sanderson-Windmeijer F-Stat 2", `: di %9.2f `SWF2'', ///
				"Kleibergen-Paap rk LM statistic", `: di %9.2f `e(idstat)'', ///
				"p-value", "[`: di %9.2f `e(idp)'']", ///
				"Mean of DV", `: di %9.2f `meandv'', "# of provinces", ///
				`e(N_clust)', "District FE", YES, "Province-year FE", YES)
